﻿@model PessMvc.Models.ArchivesModel

@{
    ViewBag.Title = "Proposal List";
    
    bool hideArchiveDetails = false;
    hideArchiveDetails = Roles.IsUserInRole("ExpertJudge")
        && ViewBag.HideArchiveDetails != null
        && ViewBag.HideArchiveDetails == true;
    int round=-1;
    if (Request["round"] != null)
    {
        round = int.Parse(Request["round"]);
    }
}
@*@Html.Partial("_ActivityNavPartial",ViewData["ActivityID"])*@
@{
    string status="";
    if(Roles.IsUserInRole("ExpertJudge")){
         status=string.Format("（Reviewed：{0}  /  Total：{1}）", Model.ReviewHistory.Count, Model.PageInfo.TotalItems);
    }
}
<h2 style="width:300px;">Review Proposals<br /><span style="font-size:12px;"> @status</span></h2>

<div id="operate">
        @if (round == -1)
        {
            <a href="#" class="button_current">
                All</a>
        }
        else
        {
            @Html.ActionLink("All", "Index", new { activityID = ViewData["ActivityID"], round = -1 }, null)
        }
        @if (round == 1)
        {
            <a href="#" class="button_current">Round 1</a>
        }
        else
        {
            @Html.ActionLink("Round 1", "Index", new { activityID = ViewData["ActivityID"], round = 1 }, null)
        }
            @if (round == 2)
            {
                <a href="#" class="button_current">
                    Round 2</a>
            }
            else
            {
                @Html.ActionLink("Round 2", "Index", new { activityID = ViewData["ActivityID"], round = 2 }, null)
            }
                @if (round == 3)
                {
                    <a href="#" class="button_current">
                        Virtual</a>
                }
                else
                {
                    @Html.ActionLink("Virtual", "Index", new { activityID = ViewData["ActivityID"], round = 3 }, null)
                }
</div>
<div>Total: @Model.All.Count()</div>
@*<p>
 @Html.DisplayFor(model => Model.SingleOrDefault().Subject.Activity.Name)
</p>*@

@*<div id="operate" class="formSearch" style="width:600px;">
       @{/*if (Roles.IsUserInRole(Membership.GetUser().UserName, "Admin") || Roles.IsUserInRole(Membership.GetUser().UserName, "CountyAdmin"))
       {
           if ((bool)ViewBag.IsArchiveModificationAllowed == true)
             {
             <div>@Html.ActionLink("New", "Create", new { activityID = ViewData["ActivityID"] }, null)</div>
             }

             if (Roles.IsUserInRole("Admin"))
             {
                 using (Html.BeginForm("ImportReviewFeedbacks", "Archive", FormMethod.Post))
                 {
                   @Html.DropDownList("SubjectID")
                   <input type="submit" value="Import Review Comments" />                    
                 }
             }
       }
       */}
    @if(!hideArchiveDetails)
    {
       <div>@Html.ActionLink("Export Proposals", "ExportArchiveList", "Archive", new {activityID=ViewData["ActivityID"]},null)</div>
   }
@*    @using(Html.BeginForm("Index","Archive",FormMethod.Get)){
            @Html.Hidden("ActivityID",ViewData["ActivityID"])
            @Html.TextBox("KeyWord")
            <input type="submit" value="Search" class="inputBtn" />
        }
</div>*@

@using(@Html.BeginForm("SetExpertGroup","Archive",FormMethod.Post)){    
    <div> @*class="grid_8 height250">  *@  
    <table id="fileList" class="oddTable">
        <thead>
    <tr>
        @if (Roles.IsUserInRole(Membership.GetUser().UserName, "Admin") || Roles.IsUserInRole(Membership.GetUser().UserName, "Chair"))
        {<th></th>}
        <th class="thSN">
            ID
        </th>
        <th class="thTitle">
            Title
        </th>
        
        <th class="thSName">
            Track
        </th>
        <th class="thCName">
            Format
        </th>
        @if (!hideArchiveDetails) { 
        <th class="thTName">
            Authors
        </th>
        @*<th class="thLevel">
           @PessResources.Archive.GradeLevel
        </th>*@
        <th class="thSCName">
            Affiliation
        </th>
        <th style="width:65px">
            Reviewer Group
        </th>
        
        }
        <th style="width:65px">
            Suggestion for Prop.
        </th>
        @if (Roles.IsUserInRole(Membership.GetUser().UserName, "Admin") || Roles.IsUserInRole(Membership.GetUser().UserName, "Chair") || Roles.IsUserInRole(Membership.GetUser().UserName, "Editor"))
        {<th>
            Proposal Status
         </th>
        }
        <th class="thAction" style="width:150px"></th>
    </tr>
            </thead>
        <tbody>
@{int x = 0;}
            @foreach (var item in Model.All) {
                var pessEC = item.ExpertComments.Where(ecc => ecc.ArchiveID == item.ID && ecc.ExpertSerialNumber == Membership.GetUser().UserName).FirstOrDefault();
                string classname = "read";
                if(User.IsInRole("Chair"))
                {
                    if (item.Status < 4)
                    {
                        classname = "unread";
                    }
                    else if (item.Status == 4)
                    {
                        classname += " paperaccept";
                    }
                    else if (item.Status == 5)
                    {
                        classname += " paperreject";
                    }
                }
                else if (User.IsInRole("ExpertJudge") )
                {
                    if(pessEC == null && item.Status < 4)
                    {
                        classname = "unread";
                    }
                    if (pessEC!=null&&pessEC.AcceptanceStatus == 1)
                    {
                        classname += " paperaccept";
                    }
                    else if(pessEC!=null&&pessEC.AcceptanceStatus==0)
                    {
                        classname += " paperreject";
                    }
                }                
        <tr class="@classname">

    
        @if (Roles.IsUserInRole(Membership.GetUser().UserName, "Admin") || Roles.IsUserInRole(Membership.GetUser().UserName, "Chair"))
        { <td>
            
            @Html.CheckBox("Archives["+x+"].IsSelected")
            @Html.Hidden("Archives["+x+"].ArchiveID",item.ID)
           
        </td> }
        <td class="thSN">
            @Html.DisplayFor(modelItem => item.CalculatedSerialNumber)
        </td>
        <td class="thTitle">
            @Html.DisplayFor(modelItem=>item.ProjectTitle)
        </td>
        <td class="thSName" title="@(Html.DisplayFor(modelItem=>item.Subject.Track.Title))">
            @Html.DisplayFor(modelItem => item.Subject.Track.ShortTitle)
        </td>
        <td class="thCName">
                @Html.DisplayFor(modelItem => item.County.Name)
        </td>
        @if (!hideArchiveDetails)
        {
        <td class="thTName" style="white-space: nowrap;">
            
                @foreach (var pa in item.PAuthors)
                {
                    @Html.DisplayFor(modelItem => pa.Name) <br />
                }
            
        </td>

        @*<td class="thLevel">
            @Html.DisplayFor(modelItem => item.GradeLevel)
        </td>*@
        <td class="thSCName">
            @if(!hideArchiveDetails)
            {
                @Html.DisplayFor(modelItem =>item.SchoolName)
            }
        </td>    
        <td>
            @if(!hideArchiveDetails)
            {
                if(item.ExpertGroup!=null){@item.ExpertGroup.Callsign}
            }
        </td>   
        }
        
        <td style="text-align:center;text-wrap:none;width:70px;">
            @if (Roles.IsUserInRole(Membership.GetUser().UserName, "ExpertJudge"))
            {
                //var pessEC = item.ExpertComments.Where(ecc => ecc.ArchiveID == item.ID && ecc.ExpertSerialNumber == Membership.GetUser().UserName).FirstOrDefault();
                if (pessEC != null)
                {
                    if (pessEC.AcceptanceStatus == 1)
                    {
                        <img src="@Url.Content("~/images/green20.png")" alt="Accepted" title="Accepted" />;
                    }
                    else
                    {
                        <img src="@Url.Content("~/images/red20.png")" alt="Rejected" title="Rejected" />;
                    }
                }
            }
            else if (Roles.IsUserInRole(Membership.GetUser().UserName, "Admin") || Roles.IsUserInRole(Membership.GetUser().UserName, "Chair")|| Roles.IsUserInRole(Membership.GetUser().UserName, "Editor"))
            {
                var pessecs = item.ExpertComments;
                foreach (var pessec in pessecs)
                {
                    if (pessec.AcceptanceStatus == 1)
                    {
                        <img src="@Url.Content("~/images/green15.png")" alt="Accepted" title="Accepted" />;
                    }
                    else
                    {
                        <img src="@Url.Content("~/images/red15.png")" alt="Rejected" title="Rejected" />;
                    } 
                }
            }
        </td>
        @if (Roles.IsUserInRole(Membership.GetUser().UserName, "Admin") || Roles.IsUserInRole(Membership.GetUser().UserName, "Chair") || Roles.IsUserInRole(Membership.GetUser().UserName, "Editor"))
        {<td>
            @item.StatusName
         </td>
        }
        <td class="thAction" style="text-align:left">
        @if (Roles.IsUserInRole(Membership.GetUser().UserName, "Admin") )
        {
            @Html.ActionLink("Details", "Details", new { id = item.ID, round = round })
            @Html.ActionLink("Delete", "Delete", new { id = item.ID, round = round })
        }
            @if (Roles.IsUserInRole(Membership.GetUser().UserName, "Editor"))
            {
                @Html.ActionLink("Details", "Details", new { id = item.ID, round = round })
            }
        @if (Roles.IsUserInRole(Membership.GetUser().UserName, "Chair"))
        {
            @Html.ActionLink("Review", "Details", new { id = item.ID, round=round })
            @*if(item.Status<4)
            {
                @Html.ActionLink("Accept", "Accept", new { id = item.ID, accept=4 })
                @Html.ActionLink("Reject", "Accept", new { id = item.ID, accept=5 })
            }*@
        }
        @if(Roles.IsUserInRole(Membership.GetUser().UserName,"ExpertJudge"))
        {
            
            if(ViewBag.IsScoreInputAllowed)
            {
                //@Html.ActionLink("评分", "Grade", new { archiveID=item.ID })
                if(item.Status==3){
                    @Html.ActionLink("Review", "Details", new { id=item.ID, round=round  });
                    if (Model.ReviewHistory.Select(r => r.ArchiveID).Contains(item.ID))
                    {
                        //<img src="@Url.Content("~/images/check20.png")" alt="Reviewed" title="Reviewed" />;
                    }
                    else
                    {
                        <img src="@Url.Content("~/images/new40.png")" alt="Unreviewed" title="Unreviewed" />;
                    }
                }
                else if(item.Status>3)
                {
                    @Html.ActionLink("Review (View Only)", "Details", new { id = item.ID, round = round });
                }

            }
            @*else
            {
                @Html.ActionLink("Review (View Only)", "Details", new { id = item.ID });
            }*@
        }
        </td>
    </tr>
    {x = x + 1;}
}
</tbody>
</table>
    <div class="clear"></div>
    </div>
<div id="pageNum">@Html.PageLinks(Model.PageInfo,u=>Url.Action("Index","Archive",new {ActivityID=Model.ActivityID,SubjectID=Model.SubjectID,Keyword=Model.Keyword,Page=u}))</div>

    if (Roles.IsUserInRole(Membership.GetUser().UserName, "Admin") || Roles.IsUserInRole(Membership.GetUser().UserName, "Chair"))
    {   
<div style="padding-top:20px;clear:both">    <span>Assign selected proposal to reviewer group: </span>

    @Html.DropDownList("ExpertGroupID",new SelectList(Model.ExpertGroups,"ID","Callsign"))
    @Html.Hidden("round", round)
    @Html.Hidden("Page", Model.PageInfo.CurrentPage)
    <input type="submit" value="Assign" class="asBtn" />
</div>
}
}
<p style="clear:both"></p>



